import { createRouter, createWebHistory, type RouteRecordRaw } from 'vue-router'

import { AccountBookOutlined } from '@ant-design/icons-vue'
import Layout from '@/layout/index.vue'
import routes from './routes'
import { routeBeforeEach } from './interception'

const router = createRouter({
  history: createWebHistory(),
  routes: [
    {
      path: '/',
      name: 'page',
      redirect: '/home',
      component: Layout,
      children: [...routes]
    },
    // 不需要权限的页面
    {
      path: '/login',
      name: 'login',
      redirect: '/login'
    },
    {
      path: '/401',
      name: '401',
      component: () => import('../views/401View.vue'),
      meta: {
        title: '401',
        icon: AccountBookOutlined
      }
    },
    {
      path: '/404',
      name: '404',
      component: () => import('../views/404View.vue'),
      meta: {
        title: '404',
        icon: AccountBookOutlined
      }
    }
  ]
})

routeBeforeEach(router)

export default router
